from src.GameConfig import *


class Progress:

    def __init__(self):
        self.max = 100
        self.progress = 0
        self.height = 2
        self.x = 0
        self.y = 0
        self.length = 100
        self.color = color_green
        self.planeRect = object

    def setMax(self, max):
        self.max = max
        self.progress = max

    def setProgress(self, progress):
        self.progress = (progress + 0)

    def setPlaneRect(self, planeRect):
        self.planeRect = planeRect
        self.length = planeRect.width

    def step(self):
        self.x = self.planeRect.x
        self.y = self.planeRect.y - 10
        if (self.progress/self.max) <= 0.5:
            self.color = color_red

    def onDraw(self, canvas):
        # draw a line from (5, 100) to (100, 100)
        # pygame.draw.line(background, (255, 0, 0), (5, 100), (100, 100))
        self.step()
        lengthx = self.x + self.length * (self.progress/self.max)
        if lengthx < self.x:
            lengthx =self.x
        pygame.draw.line(canvas, self.color,
                         (self.x, self.y),
                         (lengthx, self.y),
                         self.height)
